from rest_framework.views import APIView
from django.contrib.auth import get_user_model
from rest_framework.response import Response
from rest_framework import serializers
from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet

User = get_user_model()
class ListUsersTest3V1(APIView):

    def get(self, request, format=None):
        return Response([i.username for i in User.objects.all()])

    def post(self, request, format=None):
        return Response([i.password for i in User.objects.all()])

    def put(self, request, format=None):
        return Response([i.is_active for i in User.objects.all()])

    def delete(self, request, format=None):
        return Response([i.email for i in User.objects.all()])


class ListUsersTest3V2Serializer(serializers.Serializer):
    username = serializers.CharField(max_length=100)
    email = serializers.EmailField()
    password = serializers.CharField(max_length=100)


class ListUsersTest3V2(APIView):

    def get(self, request, format=None):
        # datas = []
        # for i in User.objects.all():


        datas = ListUsersTest3V2Serializer(User.objects.all()[0])
        return Response(datas.data)

class ListUsersTest3V3(ListAPIView):

    model = User
    queryset = User.objects.all()
    serializer_class = ListUsersTest3V2Serializer
